/* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License * Version 1.0 (the "License"). You may not use this file except in * compliance with the License. A copy of the License is available at * http://www.sun.com/ * * The Original Code is Forte for Java, Community Edition. The Initial * Developer of the Original Code is Sun Microsystems, Inc. Portions * Copyright 1997-2000 Sun Microsystems, Inc. All Rights Reserved. */ package org.netbeans.modules.search; import java.util.*; import javax.swing.*; import javax.swing.event.*; import javax.swing.border.*; import org.openide.*; import java.beans.*; import org.netbeans.modules.search.res.*; /** * Listens: PROP_STATE and PROP_CUSTOMIZED on preset model. * * @author Petr Kuzel * @version 1.0 */ public class PresetView extends JPanel implements PropertyChangeListener { private final ComboBoxModel comboModel; private final PresetModel model; /** Creates new panel based on model */ public PresetView(PresetModel model) { this.model = model; comboModel = model.getComboBoxModel(); model.addPropertyChangeListener(this); Object item = comboModel.getSelectedItem(); initComponents (); //setting combo model deleted selected item comboModel.setSelectedItem(item); EmptyBorder empty = new EmptyBorder(0,0,4,0); TitledBorder titled = new TitledBorder(Res.text("LABEL_PREDEFINED")); // NOI18N CompoundBorder border = new CompoundBorder(empty, titled); setBorder(border); saveButton.setEnabled(model.canSave()); } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the FormEditor. */ private void initComponents () {//GEN-BEGIN:initComponents useComboBox = new javax.swing.JComboBox (); defaultButton = new javax.swing.JButton (); saveButton = new javax.swing.JButton (); setLayout (new java.awt.GridBagLayout ()); java.awt.GridBagConstraints gridBagConstraints1; useComboBox.setModel (comboModel); useComboBox.addActionListener (new java.awt.event.ActionListener () { public void actionPerformed (java.awt.event.ActionEvent evt) { useComboBoxActionPerformed (evt); } } ); gridBagConstraints1 = new java.awt.GridBagConstraints (); gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints1.insets = new java.awt.Insets (4, 4, 4, 4); gridBagConstraints1.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints1.weightx = 1.0; add (useComboBox, gridBagConstraints1); defaultButton.setText (Res.text("BUTTON_DEFAULT")); defaultButton.addActionListener (new java.awt.event.ActionListener () { public void actionPerformed (java.awt.event.ActionEvent evt) { defaultButtonActionPerformed (evt); } } ); gridBagConstraints1 = new java.awt.GridBagConstraints (); gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints1.insets = new java.awt.Insets (4, 4, 4, 4); add (defaultButton, gridBagConstraints1); saveButton.setText (Res.text("BUTTON_SAVE_AS")); saveButton.addActionListener (new java.awt.event.ActionListener () { public void actionPerformed (java.awt.event.ActionEvent evt) { saveButtonActionPerformed (evt); } } ); gridBagConstraints1 = new java.awt.GridBagConstraints (); gridBagConstraints1.insets = new java.awt.Insets (4, 4, 4, 4); add (saveButton, gridBagConstraints1); }//GEN-END:initComponents /** Selected new preset value. * Update customizer values with presets. */ private void useComboBoxActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_useComboBoxActionPerformed if (! model.isInitialized() ) return; String item = (String) useComboBox.getModel().getSelectedItem(); model.usePreset(item); }//GEN-LAST:event_useComboBoxActionPerformed /** Restore default values of current preset */ private void defaultButtonActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_defaultButtonActionPerformed useComboBoxActionPerformed(null); }//GEN-LAST:event_defaultButtonActionPerformed /** Save current value as new preset */ private void saveButtonActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveButtonActionPerformed NotifyDescriptor.InputLine desc = new NotifyDescriptor.InputLine(Res.text("LABEL_NAME"), Res.text("LABEL_SAVE_CRITERION")); // NOI18N while (true) { Object obj = TopManager.getDefault().notify(desc); // if pressed ok if (obj.toString().equals("0")) { // NOI18N String name = desc.getInputText(); if (name.length()>=1) { try { model.saveAs(name); return; } catch (IllegalArgumentException ex) { // try it again } } } else { return; } } }//GEN-LAST:event_saveButtonActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JComboBox useComboBox; private javax.swing.JButton defaultButton; private javax.swing.JButton saveButton; // End of variables declaration//GEN-END:variables /** Update buttons visibility. */ public void propertyChange(final java.beans.PropertyChangeEvent e) { if (CriterionModel.PROP_CUSTOMIZED.equals(e.getPropertyName())) { saveButton.setEnabled(model.canSave()); defaultButton.setEnabled(model.canRestore()); } else if (CriterionModel.PROP_STATE.equals(e.getPropertyName())) { defaultButton.setEnabled(model.canRestore()); saveButton.setEnabled(model.canSave()); } } } /* * Log * 6 Gandalf-post-FCS1.4.1.0 4/4/00 Petr Kuzel Comments + output window * fix * 5 Gandalf 1.4 1/13/00 Radko Najman I18N * 4 Gandalf 1.3 1/10/00 Petr Kuzel Buttons enabling. * 3 Gandalf 1.2 1/5/00 Petr Kuzel Margins used. Help * contexts. * 2 Gandalf 1.1 1/4/00 Petr Kuzel Bug hunting. * 1 Gandalf 1.0 12/23/99 Petr Kuzel * $ */